Window pops only afterwords how come?

by: slicken, 7 years ago

Last edited: 7 years ago

Hi.
I have created a program and my final task is to create a window that prints the program data.
Here is my problem. The Window does only execute all the functions have runned.
I want to window to appear first, and then run functions wich sends strings to the window but the window will only appear after it have runned all the code.

For example this code below, window will only popup after the sleep function have slept, and then it creates the window. I want the window to be created first.

<pre class='prettyprint lang-py'>
------------------------------------------------
import sys, time
from PyQt4 import QtGui

class Window(QtGui.QMainWindow):
    def __init__(self):
        super(Window, self).__init__()
        self.setGeometry(700, 300, 500, 300)
        self.setWindowTitle(__file__)
        self.edit = QtGui.QTextEdit()
        self.setCentralWidget(self.edit)

    def wprint(self, string):
        self.edit.append(string)

app = QtGui.QApplication(sys.argv)
win = Window()
win.show()
win.wprint('first')
time.sleep(5)
win.wprint('second')
<pre class='prettyprint lang-py'>




You must be logged in to post. Please login or register an account.